﻿var jsdata = require("self").data;

var pageMod = require("page-mod");
pageMod.PageMod({
    include: "http://www.imdb.com/find?*",
    contentScriptWhen: 'ready',
    contentScriptFile: jsdata.url("myScript.js"),
    onAttach: function onAttach(worker) {
        worker.on('message', function (msgdata) {
            JsonLoad(msgdata, worker);
        });
    }
});

function JsonLoad(myurl, worker) {
    var Request = require("request").Request;
    Request({
        url: myurl,
        onComplete: function (response) {
            worker.postMessage(response.json);
        }
    }).get();
}